package com.film.web.controller.financial;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.film.common.annotation.Log;
import com.film.common.core.controller.BaseController;
import com.film.common.core.domain.AjaxResult;
import com.film.common.enums.BusinessType;
import com.film.financial.domain.Budget;
import com.film.financial.service.IBudgetService;
import com.film.common.utils.poi.ExcelUtil;
import com.film.common.core.page.TableDataInfo;

/**
 * 预算编制Controller
 * 
 * *@author fy
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/financial/budget")
public class BudgetController extends BaseController
{
    @Autowired
    private IBudgetService budgetService;

    /**
     * 查询预算编制列表
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:list')")
    @GetMapping("/list")
    public TableDataInfo list(Budget budget)
    {
        startPage();
        List<Budget> list = budgetService.selectBudgetList(budget);
        return getDataTable(list);
    }

    /**
     * 导出预算编制列表
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:export')")
    @Log(title = "预算编制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Budget budget)
    {
        List<Budget> list = budgetService.selectBudgetList(budget);
        ExcelUtil<Budget> util = new ExcelUtil<Budget>(Budget.class);
        util.exportExcel(response, list, "预算编制数据");
    }

    /**
     * 获取预算编制详细信息
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(budgetService.selectBudgetById(id));
    }

    /**
     * 新增预算编制
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:add')")
    @Log(title = "预算编制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Budget budget)
    {
        return toAjax(budgetService.insertBudget(budget));
    }

    /**
     * 修改预算编制
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:edit')")
    @Log(title = "预算编制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Budget budget)
    {
        return toAjax(budgetService.updateBudget(budget));
    }

    /**
     * 删除预算编制
     */
    @PreAuthorize("@ss.hasPermi('financial:budget:remove')")
    @Log(title = "预算编制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(budgetService.deleteBudgetByIds(ids));
    }
}
